﻿using AutoMapper;
using DevProtocolApi.Dtos.system;
using Model.EntityModel.Auth;
using Model.EntityModel.SysModel;

namespace DevProtocolApi.AutoMapper
{
    /// <summary>
    /// AutoMapper 配置类（映射配置文件）
    /// 用于定义对象之间的映射规则
    /// </summary>
    public class MapperProfile : Profile
    {
        /// <summary>
        /// 构造函数（配置映射规则）
        /// </summary>
        public MapperProfile()
        {
            // 示例映射配置（实际使用时替换为您的规则）：
            // CreateMap<源类型, 目标类型>()
            //     .ForMember(目标属性, opt => opt.MapFrom(源属性))
            //     .ReverseMap(); // 如需反向映射可添加

            /*------------------------------------------------------
             * 实际配置示例：
             * 1. 简单属性映射
             * CreateMap<User, UserDto>();
             *
             * 2. 自定义属性映射
             * CreateMap<Order, OrderDto>()
             *    .ForMember(dest => dest.TotalAmount,
             *       opt => opt.MapFrom(src => src.Items.Sum(i => i.Price)));
             *
             * 3. 忽略特定属性
             * CreateMap<Product, ProductDto>()
             *    .ForMember(dest => dest.SecretField, opt => opt.Ignore());
             *
             * 4. 条件映射
             * CreateMap<Employee, EmployeeDto>()
             *    .ForMember(dest => dest.IsManager,
             *       opt => opt.MapFrom(src => src.Title.Contains("Manager")));
             ------------------------------------------------------*/
            // 添加以下映射配置
            CreateMap<UserMasterDto, User>()
                .ForMember(dest => dest.PwdStatus, opt => opt.MapFrom(_ => "N")) // 设置默认密码状态
                .ForMember(dest => dest.PwdExpiryDate, opt => opt.MapFrom(_ => DateTime.Now.AddMonths(3))) // 设置密码过期时间
                .ForMember(dest => dest.LastLoginDate, opt => opt.Ignore()) // 忽略
                .ForMember(dest => dest.InactiveDate, opt => opt.Ignore()) // 忽略
                .ForMember(dest => dest.CreatedBy, opt => opt.Ignore()) // 忽略
                .ForMember(dest => dest.ModifiedBy, opt => opt.Ignore()) // 忽略
                .ForMember(dest => dest.ModifiedAt, opt => opt.Ignore()) // 忽略
                .ForMember(dest => dest.CreatedAt, opt => opt.MapFrom(_ => DateTime.Now)) // 设置创建时间
                .ForMember(dest => dest.Status, opt => opt.MapFrom(src =>
                    string.IsNullOrEmpty(src.Status) ? "A" : src.Status)) // 默认激活状态
                .ForMember(dest => dest.UserRole, opt => opt.MapFrom(src =>
                    string.IsNullOrEmpty(src.UserRole) ? "U" : src.UserRole)); // 默认用户角色

            // 保留您原有的配置
            CreateMap<DeptMasterDto, Dept>(MemberList.None).ReverseMap();

            // 配置双向映射
            CreateMap<Group, GroupMasterDto>();
            CreateMap<GroupMasterDto, Group>();
            CreateMap<Menu, MenuDto>();
            CreateMap<MenuDto, Menu>();
            
        }
    }
}